<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>模板指标</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
			<div tabid="tabA" title="基本信息" lselected="true">
	            <form id="formSet1">
	                <div class="fieldset1 tabel_col clearFix">
	                    <div class="fieldBox col_33">
		                    <div class="label">指标名称</div>
		                    <div class="field">
		                   <input name="idxNm" id="idxNm" type="text" class="ui-textbox"    value="${idxNm}" validate="{required:true}" >

		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">对应字段</div>
		                    <div class="field">
		                        <input name="idxCd" id="idxCd"   type="text" class="ui-textbox"  value="${idxCd}" validate="{required:true}">
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">指标系数</div>
		                    <div class="field">
		                        <input name="idxDesc" id="idxDesc" type="text"   class="ui-textbox"  value="${idxDesc}"  validate="{number:true}" >
		                    </div>
		                </div>
		                
		                 <div class="fieldBox col_100" style="display:none;">
	          <div class="field">
	                <input name="tmplId" id="tmplId" type="hidden" class="ui-textbox" value="${tmplId}">
                    <input name="idxId" id="idxId" type="hidden" class="ui-textbox" value="${idxId}">
	          </div>
	        </div>
				        <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div class="sqPanel_head inL">
				                    <div class="btnsBox inLC">
				                        <span id="addBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_3"></i> -->添加</span>
				                        <span id="delBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_7"></i> -->删除</span>
				                    </div>
				                </div>
				                 <br/>
				                  <br/>
				                <div id="detailGrid">
				                    <div id="ligergrid_fee" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				          <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div id="feePayGrid">
				                    <div id="ligergrid_calculate" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				        
	                </div>
	                <div class="btnsBox">

		                <span id="saveBtn1" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_10"></i> -->保存</span>
		            </div>
	            </form>
		</div>
	</div>
</div>

<script type="text/javascript">
var optGrid;//明细信息
var idxId = '${idxId}';
var detailFlag = '${detailFlag}';
var editFlag=true;
var calculateGrid;

//指标项类型
var optTypeList = [];
<c:if test="${not empty optTypeList}"> optTypeList = ${optTypeList}; </c:if>

var oprList = [];
<c:if test="${not empty oprList}"> oprList = ${oprList}; </c:if>


$(function(){

	$('#formSet1').ligerForm({
        validate : true
	});

     if(detailFlag=='false'){
     $("#addBtn").hide();
          $("#delBtn").hide();
               $("#saveBtn1").hide();
     	liger.get("idxNm").setDisabled(true);
     	
liger.get("idxDesc").setDisabled(true);
liger.get("idxCd").setDisabled(true);
         editFlag=false;
     }
		var url= '<%=path%>/system/sysscoretmpl/initIdxOptList.do?idxId='+idxId;
		idxoptGrid(url);
		
	});
	

	
	$("#saveBtn1").click(function(event) {
	    var form = liger.get("formSet1");
	    if (!form.valid()) {
	    	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
            return false; //验证不通过，不执行以下代码
        }
	  
	
				addIdxQuatPrps();
		
	
	});

	
/* 	var contAmt=$("#contAmt").val();
	if(contAmt){
	changeBaseContAmt();
	}
	 var totLsItmAmt=$("#totLsItmAmt").val();
	if(totLsItmAmt){
	 changeBaseTotLsltmAmt();
	} */

	
	function addIdxQuatPrps(){
		    var form = liger.get("formSet1");
		  var data = form.getData();
		    var detailListData = optGrid.getData();
		    var calculateData;
		    if(calculateGrid){
		     calculateData = calculateGrid.getData();
		    }
		    var tmplId = $("#tmplId").val();
		    var idxId = $("#idxId").val();
		  
         data["tmplId"]= tmplId;
         data["idxId"] = idxId;
         data["idxNm"]=$("#idxNm").val();
         data["idxCd"]=$("#idxCd").val();
         data["idxDesc"]=$("#idxDesc").val();
        
     	 data["feeDetailList"] = JSON.stringify(detailListData);
  var url = '<%=path%>/system/sysscoretmpl/idxAdd.do';
  var wait_dialog;
  $.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: url,
		beforeSend: function(){
	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	     },
		success:function(msg){
			 wait_dialog.close();
			 if(msg.success == 1){
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
				 if(msg.data){
					 $("#prpsId").val(msg.data);
					 top.$.ligerDialog.SQalert({content: "保存成功！",SQ_type: "success"});
  				  var TAB=top.mainApp.parentTab;
  			            var currentTabid=TAB.getSelectedTabItemID();
  			             var currFrameElement=top.$("#"+currentTabid).get(0);
  						 var callback=currFrameElement.W2W.callback;
			          	  		callback();
			          	 	 top.tab.removeTabItem(currentTabid);
				 }
			 }else{
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			 }
		}
	});
	} 
	
	$("#addBtn").click(function (event) {
        optGrid.addRow({});
    });
    
	$("#delBtn").click(function (event) {
        var selectedRows = optGrid.getSelectedRows();
        if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		
		
        optGrid.deleteSelectedRow();
    });
	



function deleteRow(){
	var manager = $("#ligergrid_fee").ligerGetGridManager();
	 manager.deleteSelectedRow();
}

function idxoptGrid(url){

	optGrid = $("#ligergrid_fee").ligerGrid({
		url:url,
        method: 'get',
        columns: [
         { display: '指标项编号', name: 'id', editor: { type: 'text' }, align: 'left', width: 200},
         { display: '指标项说明', name: 'optDesc', editor: { type: 'text' }, align: 'left', width: 200},
         {display: '指标项类型', name: 'optTypCd', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: optTypeList,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'optTypCd',
                textField: 'optTypNm', 
                render: function (item) {
                   item.optTypNm=getkvVal(optTypeList,item.optTypCd);
               // for(int i)
              //   if (parseInt(item.optTypCd) == 1) item.optTypNm='选项标准';
              //   if (parseInt(item.optTypCd) == 2) item.optTypNm='分段标准';
                     return item.optTypNm;
                   // return item.optTypNm;
                }
            },
         { display: '下限值', name: 'mixVal',
                    editor: { type: 'text' }, align: 'left', width: 200
                },
         {display: '下限运算符', name: 'mixOpr', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: oprList,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'mixOpr',
                textField: 'mixOprNm', 
                render: function (item) {
                 item.mixOprNm=getkvVal(oprList,item.mixOpr);
                    return item.mixOprNm;
                }
            },      
         { display: '上限值', name: 'maxVal',
                    editor: { type: 'text' }, align: 'left', width: 200
                },
         {display: '上限运算符', name: 'maxOpr', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: oprList,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'maxOpr',
                textField: 'maxOprNm', 
                render: function (item) {
                item.maxOprNm=getkvVal(oprList,item.maxOpr);
                    return item.maxOprNm;
                }
            },
            
          { display: '分值', name: 'scrVal',
                    editor: { type: 'text' }, align: 'left', width: 250
                }
        ],
       onLoaded:function(){
    	   optGrid.toggleCol('id', false);
        	this.toggleLoading(false);
        },  
        onBeforeEdit: function(e){

        var colNanme = e.column.columnname;
                          	   e.column.editor.readonly = false;
	        	if(e.record.optTypCd==1 || e.record.optTypCd=='' ){

	        	     if (colNanme == "mixVal" || colNanme == "mixOpr"||colNanme == "maxOpr") {
	
                  	   e.column.editor.readonly = true;
                     }
                     
                    if (colNanme == "optTypCd" ) {
                 //if (parseInt(item.optTypCd) == 1) return '选项标准';
               //  if (parseInt(item.optTypCd) == 2) return '分段标准';
                   // alert{e.column.valueField};
                  	   
                     }
              //   e.column.maxOpr.editor.readonly = true;
               //  e.column.mixOpr.editor.readonly = true;
              //   e.column.mixVal.editor.readonly = true;
                     }
        	
        },
        onAfterEdit: function (e) {
        /*
          var calBaseCd = e.record.calBaseCd;
          var isFixedAmt = e.record.isFixedAmt;
          var  feeTypCd = e.record.feeTypCd;
        	if(e.column.name =="feePct"){
        		var pct = e.record.feePct;
          		 var minPct = e.record.feePctMin;
            	 var maxPct = e.record.feePctMax;
            	 if(pct&&minPct&&maxPct&&feePct!="undefined"&&minPct!="undefined"&&maxPct!="undefined"){
	             	 if(feePct<minPct||feePct>maxPct){
	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "请输入"+minPct+"~"+maxPct+"之间的数值！"});
	             		  e.value = e.lastValue;
	             		 optGrid.updateRow(e.record,{
	              			feePct: e.value
	                      });
	             	 }
            	 }else{
            		 pct = Number(pct);
            		 if(typeof pct =='number'&&isFixedAmt!=1){
            			  var amt = getAmt(e.value,calBaseCd,feeTypCd,isFixedAmt);
 		             	 optGrid.updateCell('feePct', e.value, e.record);
 		             	 optGrid.updateCell('feeAmt', amt, e.record);
 		             	 }
            		 }
	             	
        	}
        	*/
        	
     /*    	
        	if(e.column.name =="feeTypCd"){
        	   	var type = e.record.feeTypCd;//获取值
            		//判断添加时是否重复添加
            		 var grid = $("#ligergrid_fee").ligerGetGridManager();
                     var data = grid.getData();
                     var  num = 0;
            		for(var i=0;i<data.length;i++){
            			if(data[i].feeTypCd==type){
                   		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "该费用选项已经存在！",});
            				break;
            			}
            		}
       	}  */

 
         	
         	
        },
        onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
          /*  if (e.selected && e.column.columnname == "feeTypCdNm") {
                e.record.feeTypCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            */
         
         //   if(e.column.columnname == "isFixedAmt" && e.selected) e.record.editable = e.selected.key;
        },
        usePager: false,
        root: 'rows',
        record: 'total',
        hideLoadButton: true,
        width: '100%',
        height: 300,
        heightDiff: -2,
        enabledEdit: editFlag,
        isScroll: false,
        checkbox: editFlag,
        rownumbers: true,
        allowUnSelectRow: true,
        alternatingRow: false,
        enabledSort: false
    });
	}
	





	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	
	function getkvVal(kv,key){
	var val="";
	for (var int = 0; int < kv.length; int++) {
	   if(key==kv[int].key){
          val=kv[int].value;
	   }
	}
	return val;
	}
</script>



</body>
</html>
